import axios from 'axios';
/**
 * 平台级别服务数据交互统一入口，例如企业信息设置，用户登录，获取用户列表、密码修改
 */
'use strict';
var platform = {
  userState:{
    '0':'未审核',
    '1':'已审核',
    '-10':'已冻结',
    '-99':'已失效'
  }
};

//登录
platform.login = function (url,success,fail) {
  url = url || '';
  axios.get('isLogin.json?url=' + url).then(function (res) {
    success(res.data);
  }).catch(fail);
};

//登出
platform.logout = function (success,fail) {
  axios.get('logoutEc',{
    baseURL:'https://passport.z-trip.cn/'
  }).then(function (rs) {
    if(rs.data.code == '0'){
      $tool.ss.removeItem('userInfo');
      axios.get('logout.json').then(res => {
        success(res.data.code == '0');
      }).catch(fail);
    }else{
      success(false);
    }
  }).catch(fail);
};

//修改用户姓名
platform.updateUserName = function (data, success, fail) {
  axios.post('members/personalInfo/updateUserName.json', data).then(function(res) {
    success(res.data);
  }).catch(fail);
}

//企业切换
platform.changePartner = function (data, success, fail) {
  axios.post('changePartner.json', data).then(function(res) {
    $tool.ss.removeItem('userInfo');
    success(res.data);
  }).catch(fail);
}

//删除证件
platform.deleteUserCert = function (data, success, fail) {
  axios.post('members/personalInfo/deleteUserCert.json', data).then(function(res) {
    success(res);
  }).catch(fail);
}

//添加证件或者修改证件
platform.saveUserCert = function (data, success, fail) {
  axios.post('members/personalInfo/saveUserCert.json', data).then(function(res) {
    success(res);
  }).catch(fail);
}

//获取性别，生日，国家基本信息
platform.getUserBaseInfo = function (success, fail) {
  axios.get('members/personalInfo/getUserBaseInfo.json').then(res => {
    success(res.data);
  }).catch(fail)
};

//获取国家列表
platform.getCountry = function (success, fail) {
  axios.get('members/personalInfo/getCountry.json').then(res => {
    success(res.data);
  }).catch(fail)
};


//获取系统更新公告信息
platform.getUpdateMsg = function (success, fail) {
  axios.get('notify/systemUpgrade.json').then(res => {
    success(res.data);
  }).catch(fail)
};

platform.getExamineList = function (status, success, fail) {
  if(status == null || status == undefined) {
    status = '';
  }
  axios.get('notify/flow/queryTaskList.json?taskStatus='+status).then(res => {
    success(res.data);
  }).catch(fail);
};

platform.getByUrl = function (url,params,success,fail) {
  axios.get(url, {
    params: params
  }).then(res => {
    success(res.data);
  }).catch(fail);
};

export default platform;
